package com.example.mybatisdemo;

import com.example.mybatisdemo.domain.Users;
import com.example.mybatisdemo.mapper.UsersMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MybatisDemo {
    public static void main(String[] args) throws IOException {
        // mybatis初始化
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        // 创建SqlSession
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //获取mapper的代理对象
        UsersMapper mapper = sqlSession.getMapper(UsersMapper.class);
        List<Users> users = mapper.queryUser(1);
        mapper.selectList(null);
        System.out.println(users);
    }
}
